package logic

import (
	"context"
	"database/sql"
	"goods/internal/model"
	"log"

	"goods/goods"
	"goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGoodsSkuLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateGoodsSkuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodsSkuLogic {
	return &CreateGoodsSkuLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 规格
func (l *CreateGoodsSkuLogic) CreateGoodsSku(in *goods.CreateGoodsSkuRequest) (*goods.CreateGoodsSkuResponse, error) {
	// todo: add your logic here and delete this line
	GoodsSku := model.GoodsSku{
		DishId: in.Data.DishId,
		Name:   sql.NullString{String: in.Data.Name, Valid: true},
		Value:  sql.NullString{String: in.Data.Value, Valid: true},
	}
	_, err := l.svcCtx.GoodsSku.Insert(context.Background(), &GoodsSku)
	if err != nil {
		log.Println("添加商品失败")
	}
	return &goods.CreateGoodsSkuResponse{Code: 200, Msg: "添加商品成功"}, nil
}
